import React, { Component, PropTypes } from 'react';
import $ from "jquery";
import action from '../../../Action/Index';

class ListItem2 extends Component {
    constructor(props) {
        super(props)
        this.state = {
            isFreshing: false
        }

        this.onToggleGroup = (e) => {
            if (!this.state.isFreshing) {
                this.setState({
                    isFreshing: true
                })
            }

            let id = e.target.id;
            let text = $(e.target).text();

            let Gid = $("#showRender a:last").attr('id');
            let Gtext = $("#showRender a:last").text();

            $("#showRender a:last").text(text);
            $("#showRender a:last").attr('id', id);

            $(e.target).text(Gtext);
            $(e.target).attr('id', Gid);

            $("#showRender a:last").siblings().removeClass('active');
            $("#showRender a:last").addClass('active');

            $('.js_classify_pull').hide('5000');
            $(".tit-down i").removeClass('down');
 
            this.onClickGroup(id)
            setTimeout(_ => {
                this.setState({
                    isFreshing: false
                })
            }, 3000)
        }
    }
    onClickGroup(id) {
        let {dispatch} = this.props;
        dispatch(action.fetchGroupItem(id));
    }
    render() {
        let {id, classifyName, sort} = this.props;

        return (
            <a className="mui-col-xs-3 render-item-pull mui-ellipsis" onClick={this.onToggleGroup} id={id} href="javascript://">{classifyName}</a>
        );
    }
    shouldComponentUpdate(np) {
        return false;
        // return this.props.tab !== np.tab; //tab和之前的不一致，组件才需要更新，否则不更新，提升性能
    }
}

export default ListItem2;